﻿<%@ WebHandler Language="C#" Class="LoadHouseInfo" %>

using System;
using System.Web;
using System.Data;
using DalEx;

public class LoadHouseInfo : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string type = context.Request.QueryString["ty"].ToString();
        if (type == "1"){
            DataTable mydt = DbHouseRegionEx.Select(" and BaoMing=" + context.Request.QueryString["F"].ToString()).Tables[0];
            for (int i = 0; i < mydt.Rows.Count; i++)
            {
                context.Response.Write("<option value=\"" + mydt.Rows[i]["HouseRegionID"] + "\">" + mydt.Rows[i]["HouseRegionName"] + "</option>");
                context.Response.Write("<option value=\"other\">其它</option>");
            }
        }
        else if (type == "2")
        {
            if (context.Request.QueryString["rID"].ToString() != "other")
            {
                DataTable mydt = DbHouseGroupEx.Select(" and houseRegionID=" + context.Request.QueryString["rID"].ToString()).Tables[0];
                if (mydt.Rows.Count < 1)
                {
                    context.Response.Write("<option value=\"\">" + "无" + "</option>");
                }
                else
                {
                    context.Response.Write("<option value=\"0\">请选择</option>");
                    for (int i = 0; i < mydt.Rows.Count; i++)
                    {
                        context.Response.Write("<option value=\"" + mydt.Rows[i]["HouseGroupID"] + "\">" + mydt.Rows[i]["HouseGroupName"] + "</option>");
                    }
                }
            }
        }
        else if (type == "3")
        {
            string t = context.Request.QueryString["t"].ToString();
            DataTable mydt;
            if (t == "0") {
                mydt = DbHouseNumberEx.Select(" and HouseGroupID=" + context.Request.QueryString["gID"].ToString() + " and HouseNumberType=" + context.Request.QueryString["t"].ToString()).Tables[0];  
            }
            else
            {
                if (!string.IsNullOrEmpty(context.Request.QueryString["nID"])) { 
                    mydt = DbHouseNumberEx.Select(" and ParentID=" + context.Request.QueryString["nID"].ToString() + " and HouseNumberType=" + context.Request.QueryString["t"].ToString()).Tables[0];
                } 
                else
                {
                    mydt = DbHouseNumberEx.Select(" and HouseGroupID=" + context.Request.QueryString["gID"].ToString() + " and HouseNumberType=" + context.Request.QueryString["t"].ToString()).Tables[0];
                } 
                if (mydt.Rows.Count < 1)
                {
                    mydt = DbHouseNumberEx.Select(" and HouseGroupID=" + context.Request.QueryString["gID"].ToString() + " and HouseNumberType=" + context.Request.QueryString["t"].ToString()).Tables[0];
                }
            }
            if (mydt.Rows.Count < 1)
            {
                context.Response.Write("<option value=\"\">" + "无" + "</option>");
            }
            else
            {
                context.Response.Write("<option value=\"\">请选择</option>");
                for (int i = 0; i < mydt.Rows.Count; i++)
                {
                    context.Response.Write("<option value=\"" + mydt.Rows[i]["HouseNumberID"] + "\">" + mydt.Rows[i]["HouseNumberName"] + "</option>");
                }
            }
           
        }
        else if (type == "4") {
            DataTable mydt = DbAreaEx.Select().Tables[0];
            context.Response.Write("<option value=\"\">" + "请选择" + "</option>");
            for (int i = 0; i < mydt.Rows.Count; i++)
            {
                 context.Response.Write("<option value=\"" + mydt.Rows[i]["AreaID"] + "\">" + mydt.Rows[i]["AreaName"] + "</option>");
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}